import { createRouter, createWebHistory } from 'vue-router'
import LayoutView from '../views/Layout/LayoutView.vue'
import LoginView from '../views/LoginView.vue'
import GameInfo from '../views/GameInfo.vue'
// import HomeView from '../views/HomeView.vue'
import IconView from '@/views/IconView.vue'
import HomeView from '@/views/HomeView.vue'
import GamePreview from '@/views/GamePreview.vue'
import JSONView from '@/views/Tool/JSONView.vue'
import LinkView from '@/views/Tool/LinkView.vue'
const mainRouter = [
  {
    path: '/',
    name: 'login2',
    component: LoginView
  },
  {
    path: '/login',
    name: 'login',
    component: LoginView
  },
  {
    path: '/game2',
    name: 'game2',
    component: GameInfo
  }
]
export const layoutRouter = [
  {
    path: '/main',
    name: '主页',
    component: LayoutView,
    meta: { icon: 'HomeFilled', hasChildren: false },
    params: {t:Date.now},
    children: [
      {
        path: '',
        name: '主页',
        component: HomeView
      }
    ]
  },
  {
    path: '/game',
    name: '游戏',
    component: LayoutView,
    params: {t:Date.now},
    meta: { icon: 'HomeFilled', hasChildren: true },
    children: [
      {
        path: 'preview',
        name: '游戏预览',
        params: {t:Date.now},
        component: GamePreview
      },
      {
        path: 'gameInfo',
        name: '游戏详情',
        component: GameInfo
      }
    ]
  },
  {
    path: '/icon',
    name: '',
    component: LayoutView,
    meta: { icon: 'HomeFilled', hasChildren: false, requiresAuth: true },
    children: [
      {
        path: 'index',
        name: '图标',
        component: IconView
      }
    ]
  },
  {
    path: '/tool',
    name: '工具',
    meta: { icon: 'HomeFilled', hasChildren: true },
    component: LayoutView,
    children: [
      {
        path: 'json',
        name: 'json',
        component: JSONView
      },
      {
        path: 'link',
        name: '网页',
        component: LinkView
      }
    ]
  }
]
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: mainRouter.concat(layoutRouter)
})
router.beforeEach((to, from, next) => {
  if (to.fullPath === '/login') {
    next()
  } else {
    next()
    // if(to.matched.some(record => !record.meta.requiresAuth)){
    //   next({
    //     path:'/login'
    //   });
    // }else{
    //   next();
    // }
  }
  console.log(to, from,next)

  // next({
  //   path:'/login'
  // });
})
export default router
